'''
Created on Aug 10, 2012

@author: peng
'''
import happybase

connection = happybase.Connection('10.2.1.247',
                                  compat='0.90',
                                  table_prefix='beluga_analysis',
                                  autoconnect=False)
connection.open()

tables = connection.tables()
print tables
# table = connection.table('duration_distribution')
# table = connection.table('custom_event')
# table = connection.table('error_track')
table = connection.table('basic_statistics')
# table = connection.table('version')

app_keys = ['240bffab92804697ab5dd70db5a34b03',
            '364c9bb1757a488b9531f4bacd0dd054',
            '4bf843b60bb747349eb38077aaf656cc',
            '4f71366ef32ec4837e3ece8a1ab72bb6',
            '566dc366dc4b47afa2dba20e515aeec7',
            '6e1cd3bc2cda139a29b552ae5d742b80',
            '6fffbab91bbf426693c4d71978ca863e',
            '79d1710f70c5dcbc08dd4604a3909f16',
            'b446addb522940ebaa35e3d8bef08880',
            'd4061a11a85bc92c3cb60526ddfbc463']

dates = ['20121001',
        '20121002',
        '20121003',
        '20121004',
        '20121005',
        '20121006',
        '20121007',
        '20121008',
        '20121009',
        '20121010',
        '20121011',
        '20121012',
        '20121013',
        '20121014',
        '20121015',
        '20121016',
        '20121017',
        '20121018',
        '20121019',
        '20121020',
        '20121021',
        '20121022',
        '20121023',
        '20121024']

for date in dates:
    for app_key in app_keys:
        prefix = [app_key, date]
        rows = table.scan(row_prefix='\t'.join(prefix))
        print app_key + ' ' + date
        for key, data in rows:
#            table.delete(key)

connection.close()
